import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'home_logic.dart';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    final HomeLogic logic = Get.find<HomeLogic>();
    final state = logic.state;

    return Scaffold(
        body: SafeArea(
            child: PageView(
                controller: logic.pageController,
                onPageChanged: (p) {
                  logic.changePage(p, false);
                },
                children:
                    state.tabData.map((element) => element.page).toList())),
        bottomNavigationBar: Obx(() {
          return BottomNavigationBar(
              backgroundColor: Colors.white,
              items: state.tabData.map((element) => element.bottom).toList(),
              currentIndex: state.currentIndex.value,
              selectedLabelStyle: const TextStyle(fontWeight: FontWeight.w600),
              selectedItemColor: Colors.black,
              selectedIconTheme:
                  const IconThemeData(color: Colors.orangeAccent),
              onTap: (i) {
                logic.changePage(i, true);
              },
              type: BottomNavigationBarType.fixed);
        }));
  }
}
